﻿<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>表面分析</title>
        <style type="text/css">
            body{
                margin: 0;
                overflow: hidden;
                background: #fff;
            }
            #map{
                position: relative;
                height: 510px;
                border:1px solid #3473b7;
            }
            #toolbar {
                position: relative;
                padding-top: 5px;
                padding-bottom: 10px;
            }
        </style>
        <link href='./css/bootstrap.min.css' rel='stylesheet' />
        <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            var map, local, baseLayer, resultLayer, Spatialanalyst_sample,
            points = new SuperMap.Geometry.LinearRing([
                new SuperMap.Geometry.Point(0,4010338),
                new SuperMap.Geometry.Point(1063524,4010338),
                new SuperMap.Geometry.Point(1063524,3150322),
                new SuperMap.Geometry.Point(0,3150322)
            ]),
            region = new SuperMap.Geometry.Polygon([points]),
            host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host,
            url=host+"/iserver/services/map-temperature/rest/maps/全国温度变化图",
            url2=host+"/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
            function init(){
                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })], units: "m"
                });
                map.allOverlays = true;
                baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("全国温度变化图", url, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
                baseLayer.events.on({"layerInitialized":addLayer});
                resultLayer = new SuperMap.Layer.Vector("等值线");
            }

            function addLayer() {
                map.addLayers([baseLayer, resultLayer]);
                map.setCenter(new SuperMap.LonLat(531762, 3580330), 2);
            }
            function surfaceAnalystProcess() {
                resultLayer.removeAllFeatures();
                var surfaceAnalystService = new SuperMap.REST.SurfaceAnalystService(url2),
                        surfaceAnalystParameters = new SuperMap.REST.SurfaceAnalystParametersSetting({
                            datumValue: 0,
                            interval: 2,
                            resampleTolerance: 0,
                            smoothMethod: SuperMap.REST.SmoothMethod.BSPLINE,
                            smoothness: 3,
                            clipRegion: region
                        }),
                        params = new SuperMap.REST.DatasetSurfaceAnalystParameters({
                            extractParameter: surfaceAnalystParameters,
                            dataset: "SamplesP@Interpolation",
                            resolution: 3000,
                            zValueFieldName: "AVG_TMP"
                        });
                surfaceAnalystService.events.on({"processCompleted": surfaceAnalystCompleted, "processFailed": surfaceAnalystFailed});
                surfaceAnalystService.processAsync(params);
            }

            function surfaceAnalystCompleted(args) {
                var features = args.result.recordset.features;
                for (var len=features.length,i=0;i<len;i++) {
                    style = {
                        strokeColor:"#304DBE",
                        fillOpacity:0
                    }
                    features[i].style = style;
                }
                resultLayer.addFeatures(args.result.recordset.features);
            }

            function surfaceAnalystFailed(args) {
                alert(args.error.errorMsg);
            }

            function removeData() {
                resultLayer.removeAllFeatures();
            }
        </script>
    </head>
    <body onload="init()">
        <div id="toolbar">
            <input type="button" class="btn" value="提取等值线" onclick="surfaceAnalystProcess()" />
            <input type="button" class="btn" value="移除" onclick="removeData()" />
        </div>
        <div id="map"></div>
    </body>
</html>
